import fs from 'node:fs';

const files = fs.readdirSync('./plugins/qiqi-plugin/apps').filter(file => file.endsWith('.js'))

let ret = []

logger.info('--------------------------------------------')
logger.info('         七七初始化中~~~')
logger.info('                   _oo0oo_')
logger.info('                  o8888888o')
logger.info('                  88" . "88')
logger.info('                  (| -_- |)')
logger.info('                  0\  =  /0')
logger.info('                ___/`---`\__')
logger.info('              .` \\|     |/  `.`')
logger.info('             / \\|||  :  |||// \`_')
logger.info('            / _||||| -:- |||||- \`')
logger.info('           |   | \\\  - /// |   |')
logger.info('           | \_|  ``\---/``  |_/ |`')
logger.info('           \  .-\__  '-'  ___/-. /')
logger.info('---------------------------------------------- ' )
logger.info('        佛祖保佑                 永无BUG '   )
logger.info('        佛祖保佑                 永无BUG '   )


files.forEach((file) => {
    ret.push(import(`./apps/${file}`))
})

ret = await Promise.allSettled(ret)

let apps = {}
for (let i in files) {
    let name = files[i].replace('.js', '')

    if (ret[i].status != 'fulfilled') {
        logger.error(`载入插件错误：${logger.red(name)}`)
        logger.error(ret[i].reason)
        continue
    }
    apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
}


export { apps }